<?php
$obj = $self->getFormObject();
$tags = $obj->getTags();
$tag_str = count($tags) ? $tags->getTagString() : '';
?>
<div id="tag_tab" class="section">
	<div class="section-head">
		<h4>Tags</h4>
	</div>
	<div class="section-fieldset">
		<div class="control-group">
			<label class="control-label" for="txtTag" >Post's tags</label>
			<div class="controls">
				<input type="text" id="txtTag" name="tags" class="input-xxlarge" value="<?php echo $tag_str ?>" placeholder="Separate tags with commas"/>
				<a id="btnAllTag" href="#" title="Browse all tags">[...]</a>

				<div id="overlay" style="display: none"></div>
				<div id="tag-form" style="display:none">
					<button class="close" type="button">x</button>
					<div class="modal-header">
						<h3>Select tags</h3>
					</div>
					<div class="modal-body">
					<?php $tags = $self->getTags(); ?>
					<ul class="all-tags">
						<?php foreach($tags as $tag): ?>
						<li>
						<label>
							<input type="checkbox" value="<?php $tag->getId() ?>" />
							<?php echo $tag->getName() ?>
						</label>
						</li>
						<?php endforeach ?>
					</ul>
					</div>
				</div>
				
				<script type="text/javascript">
				//<![CDATA[
				// create dialog
				var tagForm = new TagForm('tag-form', { 
					onHide: function() {
						$('#txtTag').val(this.getTags().join(', ')); 
					} 
				});

				// show dialog
				$('#btnAllTag').click(function (e) {
					tagForm.setTags($('#txtTag').val());
					tagForm.show();
					e.preventDefault();
				});
				//]]>
				</script>
			</div>
		</div>
	</div>
</div>